import logging
from script.init_log_config import init_log_config

import requests
import pytest

class TestLogin:

    init_log_config()

    base_url = "http://ihrm2-test.itheima.net/api/sys/login"

    def get_response(self,username,password):
        req_json = {"mobile":username,"password":password}
        response = requests.post(url=self.base_url, json=req_json)
        # print(response.json())
        logging.info(response.json())
        logging.error(response.json())

        return response

    @pytest.mark.parametrize("mobile, password, expected_status, expected_success, expected_message",[
        ("13800000002", "888itcast.CN764%...", 200, True, "操作成功"),
        ("13800004334", "888itcast.CN764%...", 200, False, "用户名或密码错误")
    ])
    def test_1_login(self, mobile, password, expected_status, expected_success, expected_message):
        response = self.get_response(mobile, password)
        assert response.json()["success"] == expected_success
        assert response.status_code == expected_status
        assert expected_message in response.json()["message"]
        # print(mobile)
        logging.info(mobile)
        logging.error(mobile)

if __name__ == '__main__':
    pytest.main(['-s', 'log_1.py'])
